<?php
class WordController extends AppController {

	public $name = 'word';

	function beforeFilter() {
	    parent::beforeFilter(); 
		$this->C_auth->autoRedirect = false; //For override login
	    $this->C_auth->allowedActions = array('index','worddel','wordedit','wordadd');

	}

	public function index() {
        $page = Request::get_args('page');
        $url_this = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'];
        $tb = array('model' => 'word',
				    'fields' => array('word.*'),
					'conditions' => '',
					'order' => '',
					'limit' => '10',
					'group' => '',
					'url' => preg_replace("/&page=([^&]+)/","",$url_this),
					'page' => $page,
					'plist' => 6				
				); 
	    $result =  $this->fpage($tb);
        $this->set('result',$result);		
	}	
	public function wordadd() {        	
	    if(isset($this->data)) {
            /* post 数据处理 */
            $post['word_name'] = Request::get_args("word_name");
            $post['content'] = Request::get_args("content");
            $post['add_time'] = date("Y-m-d H:i:s");
	        $safeData['word'] = $post;			
			$query = $safeData;
			if (POP::exe('[@@:UM word][@@:QU save]',$query)) {			
                $this->flash("修改成功！", Router::url('admin/word/index/'));		        
            } else {	           
			    $this->flash("修改失败！", Router::url('admin/word/index/'));   
            }			
		}
	}	
	
	public function wordedit() {	
	    if(isset($this->data)) {
            /* post 数据处理 */
            $word_id = intval(Request::get_args('word_id'));
            $word_name = Request::get_args('word_name');
            $content= Request::get_args('content');		
            $add_time = date("Y-m-d H:i:s");
			$query  = array();		
			$query['keyid'] = $word_id;
			$safeData['word'] = array('word_name' => $word_name,'content' => $content,'add_time' => $add_time);				
			$query['set'] = $safeData;		
            if(POP::exe('[@@:UM word][@@:QU save]',$query)) {			
                $this->flash("修改成功！", Router::url('admin/word/index/'));		        
            } else {	           
			    $this->flash("修改失败！", Router::url('admin/word/index/'));   
            }			
		}else {
	        $id=intval(Request::get_args('id'));
            if(!$id) { 
		        $this->flash("参数错误！", Request::referer()); 
		    }
			$query = array(
				'conditions' => array('word.id' => $id), 
				'fields' => array('word.*'), 
			);
			$row = POP::exe('[@@:UM word][@@:QU find:first]',$query);	
		    $row = $row['word'];
            $this->set('row',$row);
        }		
	}		
	
	public function worddel() {
	    $word_id=Request::get_args('word_id');
	    if($word_id){
		    $id=implode(",", $word_id);
	    }else{
		    $id = intval(Request::get_args('id'));
	    }	
        if(!$id) { 
		    $this->flash("参数错误！", Request::referer()); 
		}
		$query = array('conditions'=>array('word.id' => $id));			
        if(POP::exe('[@@:UM word][@@:QU del]',$query)) {
            $this->flash("删除成功！", Router::url('admin/word/index/'));		        
        } else {	           
			$this->flash("删除失败！", Router::url('admin/word/index/'));   
        }	
	}	
	

}


?>